<template>
	<view>
		<view class="content">
			<view class="tips">
				<view class="tipsTop">
					忘记密码
				</view>
				<view class="tipsBom">
					请输入手机号码和验证码找回密码
				</view>
			</view>

			<view class="main">
				<view class="iptBox">
					<view class="iptTitle">
						手机号码
					</view>
					<view class="iptMain flex-between">
						<input class="ipt" type="text" placeholder="请输入手机号码" v-model="form.account">
					</view>
				</view>

				<view class="iptBox">
					<view class="iptTitle">
						验证码
					</view>
					<view class="iptMain flex-between">
						<input class="ipt" type="text" placeholder="请输入验证码" v-model="form.captcha">
						<button class="capBtn" :plain="true"
							@click="sendMsg()">{{sendVerifyLoad?`${downTime}S`:'获取验证码'}}</button>
					</view>
				</view>

				<view class="iptBox">
					<view class="iptTitle">
						请输入新密码
					</view>
					<view class="iptMain flex-between">
						<input class="ipt" type="password" placeholder="6-20位字符，可使用数字、字母或符号的组合" v-model="form.password">
					</view>
				</view>

				<view class="iptBox">
					<view class="iptTitle">
						请再次输入新密码
					</view>
					<view class="iptMain flex-between">
						<input class="ipt" type="password" placeholder="6-20位字符，可使用数字、字母或符号的组合"
							v-model="form.password2">
					</view>
				</view>

				<button class="completeBtn" :plain="true" @click="onCompleteBtn">
					<view class="lineBox flex">
						<view class="line"></view>
						<view class="line2"></view>
					</view>
					完成
				</button>

				<view class="others flex-around">
					<view class="leftLine"></view>
					<view class="othersText">
						技术支持：伯贝网络有限公司
					</view>
					<view class="rightLine"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					account: "",
					captcha: "",
					password: "",
					password2: "",
				},

				downTime: 60,
				sendVerifyLoad: false
			}
		},
		onShow() {

		},
		methods: {
			sendMsg() {
				if (!this.form.account) {
					uni.showToast({
						title: '请输入手机号',
						icon: "none",
						duration: 1500,
					})
					return
				}
				if (this.sendVerifyLoad) {
					uni.showToast({
						title: `请等待${this.downTime}s后继续操作`,
						icon: "none",
						duration: 1500,
					})
					return
				}
				this.sendVerifyLoad = true
				this.$post({
					module: 'Account',
					interface: 1003,
					data: {
						account: this.form.account
					}
				}).then(res => {
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 1500,
					})
					let time = setInterval(() => {
						this.downTime--;
						if (this.downTime <= 0) {
							this.downTime = 60;
							this.sendVerifyLoad = false;
							clearTimeout(time);
						}
					}, 1000);
				}).catch(() => {
					this.sendVerifyLoad = false;
				})
			},
			onCompleteBtn() {
				if (!this.form.account) {
					uni.showToast({
						title: '请输入手机号',
						icon: "none",
						duration: 1500,
					})
					return
				}
				if (!this.form.captcha) {
					uni.showToast({
						title: '请输入短信验证码',
						icon: "none",
						duration: 1500,
					})
					return
				}
				if (!this.form.password) {
					uni.showToast({
						title: '请输入密码',
						icon: "none",
						duration: 1500,
					})
					return
				}
				if (this.form.password != this.form.password2) {
					uni.showToast({
						title: '两次密码输入不一致',
						icon: "none",
						duration: 1500,
					})
					return
				}
				this.$post({
					module: "Account",
					interface: 1004,
					data: this.form
				}).then(res => {
					// console.log(res);
					uni.showToast({
						title: res.message,
						icon: "none",
						duration: 1500,
					})
					uni.navigateTo({
						url: '/pages/login/login'
					})
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.content {
		padding: 8rpx 0 0;

		.tips {
			padding-left: 30rpx;

			.tipsTop {
				font-size: 40rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #000000;
				line-height: 47rpx;
			}

			.tipsBom {
				font-size: 24rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #999999;
				line-height: 28rpx;
				margin-top: 16rpx
			}
		}

		.main {
			height: 1232rpx;
			background: linear-gradient(180deg, #FFF5F4 0%, #FFFFFF 14%);
			border-radius: 24rpx 24rpx 0px 0px;
			margin-top: 34rpx;
			padding: 56rpx 56rpx 0;

			.iptBox {
				margin-bottom: 24rpx;

				.iptTitle {
					font-size: 28rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: normal;
					color: #120C45;
					line-height: 33rpx;
				}

				.iptMain {
					width: 630rpx;
					height: 100rpx;
					background: #FFFFFF;
					box-shadow: 0px 4rpx 8rpx 0px rgba(212, 212, 212, 0.25);
					border-radius: 30rpx;
					margin-top: 22rpx;
					padding: 0 32rpx 0 50rpx;

					.ipt {
						flex: 1;
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: normal;
						color: #7E7B97;
						line-height: 28rpx;
						border: none;
						outline: none;
						background-color: transparent;
					}

					.capBtn {
						font-size: 24rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: normal;
						color: #F2615F;
						line-height: 28rpx;
						padding: 6rpx 24rpx;
						border-radius: 23rpx;
						border: 1px solid #D7D7D7;
						margin: 0;

					}
				}
			}

			.completeBtn {
				width: 630rpx;
				height: 100rpx;
				background: #F2615F;
				border-radius: 50rpx;
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 33rpx;
				padding: 0;
				margin: 202rpx 0 0;
				border: none;
				position: relative;

				.lineBox {
					position: absolute;
					top: 12rpx;
					left: 42rpx;

					.line {
						width: 17rpx;
						height: 3rpx;
						background: #FFFFFF;
						border-radius: 2rpx;
					}

					.line2 {
						width: 55rpx;
						height: 3rpx;
						background: #FFFFFF;
						border-radius: 2rpx;
						margin-left: 6rpx;
					}
				}
			}

			.others {
				margin-top: 46rpx;

				.leftLine {
					width: 132rpx;
					height: 2rpx;
					background: linear-gradient(270deg, rgba(192, 192, 192, 1), rgba(0, 0, 0, 0));
				}

				.othersText {
					font-size: 16rpx;
					font-family: PingFang SC-Semibold, PingFang SC;
					font-weight: normal;
					color: #ACB8C1;
					line-height: 23rpx;
				}

				.rightLine {
					width: 132rpx;
					height: 2rpx;
					background: linear-gradient(90deg, rgba(192, 192, 192, 1), rgba(0, 0, 0, 0));
				}
			}
		}
	}
</style>
